home *** CD-ROM | disk | FTP | other *** search
/ boe.pres.k12.wv.us / boe.pres.k12.wv.us.zip / boe.pres.k12.wv.us / Utilities / Xerox Workcentre 5335 / Windows Scan / 32-bit_x86 / Russian / cpsimage.cab / data / xipProcs / scanXMLtoXIPXML.proc < prev    next >
Text File  |  2009-03-16  |  3KB  |  85 lines

  1. // $Id: scanXMLtoXIPXML.elf,v 1.11 2008/07/10 21:45:42 kingsley Exp $ 
  2.  
  3. #load "xipProcs/scanCSDKtoXIPXML.proc";
  4. #load "xipProcs/printLayer.proc";
  5. #import "documentio.ucm";
  6. #load "docio/doctransforms.elf";
  7. LoadClasses(filename: "xeng"); 
  8. /* @scanXMLtoXIPXML
  9.   //DESCRIPTION
  10.   Takes an input PDF or XPS file (indoc) containing XML generated by CSDK (Nuance OCR format).
  11.   It read the PDF file and transforms the text to a XIPIMAGE with XIPXML text layer.
  12.   It then adds it to the original file as a new PDF or XPS document.
  13. */
  14.  
  15. PROCEDURE scanXMLtoXIPXML ( STRING file, STRING indoc, STRING outdoc)
  16. {
  17.     INTEGER outPageCount;
  18.     INTEGER i, rotation;
  19.     DOUBLE sfXpos, sfYpos;
  20.     DOUBLE xres, yres;
  21.     XIPIMAGE sfdoc, xmlImage, inDocPage; 
  22.     BOOLEAN sameimg;  
  23.    
  24.     // Create document reader and read original pdf document
  25.     DOCUMENTREADER docReader = CreateDocumentReader(filename:indoc);
  26.     DOCUMENTWRITER docWriter = CreateDocumentWriter(filename:outdoc);
  27.  
  28.     INTEGER pageCount = docReader.getPageCount();
  29.     LIST ops; 
  30.     // Prepare scaling factor from original document  - use height and width
  31.     for(i = 1; i < pageCount+1; i++){  
  32.         inDocPage = docReader.getPage(pgnum: i);
  33.        rotation = inDocPage.getAttr(name: "_PDFrotate");
  34.     if(rotation > 0){
  35.         //ops.insert(name: "IOP_rotate", obj: 90); 
  36.         //SetWriterSpecs(dwrter:docWriter, oper:ops); 
  37.         TransformPage(inpage: inDocPage, todoc: docWriter, doTrace: TRUE)
  38.                   Returns (isOriginal: sameimg, outpage: sfdoc);
  39.     }else{
  40.         sfdoc = inDocPage; 
  41.     }
  42.     
  43.     sfXpos = sfdoc.getMember(member: "xpos" );
  44.         sfYpos = sfdoc.getMember(member: "ypos" );
  45.         xres = sfdoc.resolution[0];
  46.         yres = sfdoc.resolution[1];
  47.  
  48.         // Get XML from scanned XML
  49.         xmlImage = scanCSDKtoXIPXML(filename:file, pgnumber: i, yres:yres, xres:xres);
  50.  
  51.         // Add data from original doc to xmlImage
  52.         xmlImage.resolution = (sfdoc.resolution[0],sfdoc.resolution[1]);
  53.         xmlImage.setMember(num:0, member: "xres", value: sfdoc.resolution[0]);
  54.         xmlImage.setMember(num:0, member: "yres", value: sfdoc.resolution[1]);
  55.         xmlImage.imageHeight = sfdoc.imageHeight;
  56.         xmlImage.imageWidth = sfdoc.imageWidth; 
  57.         xmlImage.setMember(num:0, member: "height", value: sfdoc.imageHeight);
  58.         xmlImage.setMember(num:0, member: "width", value: sfdoc.imageWidth);
  59.  
  60.         // Left here for comparison - seems to work better without using xpos or ypos
  61.         //xmlImage.setMember(num:0, member: "xpos", value: sfXpos);
  62.         //xmlImage.setMember(num:0, member: "ypos", value: -sfYpos);
  63.  
  64.         // set up TEXT info
  65.         xmlImage.setMember(num:0, member: "charCount", value: 0);
  66.         xmlImage.setMember(num:0, member: "textType", value: XIP_XML_TEXT);
  67.  
  68.         // debug
  69.         // xmlImage.Write(filename: "csdk-data.txt");
  70.  
  71.  
  72.        
  73.         // Add xml to original document
  74.         sfdoc.addLayer(image:xmlImage, lindex:0);        
  75.  
  76.  
  77.         // Append page to new document
  78.     
  79.         outPageCount = docWriter.appendPage(pgImg:sfdoc);
  80.     }
  81.     
  82.     docWriter.release();
  83.     docReader.release();
  84. }
  85.